package com.homwee.factory.pageData;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;
import android.app.AlertDialog;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.IntentFilter;
import android.content.Intent;
import android.content.ComponentName;

import com.homwee.factory.FactoryActivity;
import com.homwee.factory.FactoryListInfoActivity;
import com.homwee.factory.R;
import com.homwee.factory.util.Contants;
import com.homwee.listMenu.util.MenuItemData;
import com.mediatek.twoworlds.factory.MtkTvFApiInformation;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class PageData0 extends PageData {

	// boolean waitflag =false;
	String HdcpKey1_0 = "Checking...";
	String HdcpKey2_2 = "Checking...";
	String WidevineKey = "Checking...";
	String CIKey = "Checking...";
	String ESNKey = "Checking...";
	String KeyMaster = "Checking...";
	String PlayReadyKeyStr = "Checking...";
	String PlayReady25KeyStr = "Checking...";
	String CLIENTCAKeyStr = "Checking...";
	String HashKeyStr = "Checking...";
	String MacStr = "Checking...";
	String DeviceIdStr = "Checking...";
	String ESNID = "Checking...";

	boolean isWidevineKeyExist = false;
	boolean isHDCPKey1XExist = false;
	boolean isHDCPKey2XExist = false;
	boolean isDTVCIPlusKeyExist = false;
	boolean isESNKeyExist = false;
	boolean isKeyMasterExist = false;
	boolean isPlayReadyKeyExist = false;
	//PLAYREADY25 is no need in android r
	// boolean isPlayReady25KeyExist = false;
	boolean isCLIENTCAkeyExist = false;
	boolean isHashKeyExist = false;
	boolean isMacExist = false;
	boolean isDeviceIdExist = false;
	boolean isESNIDExist = false;
	boolean isAllKeyExist = false;

	public static final int KEY_STATUS_CHECK = 4;
	private Context context;
	public static Toast mToast = null;
	public static final String mBrand = android.os.Build.BRAND;
	public static final String mBuildProduct = android.os.Build.PRODUCT;

	public PageData0(Context context, FactoryActivity mFactoryActivity) {
		super(mFactoryActivity);
		this.context = context;

	}

	Handler mhandler = new Handler();
	Runnable mRun = new Runnable() {

		@Override
		public void run() {

			Map<String, String> keyMap = new HashMap<String, String>();

			isWidevineKeyExist = factorySetting.isWidevineKeyExist();
			WidevineKey = isWidevineKeyExist ? "OK" : "NG";
			keyMap.put("Widevine", WidevineKey);

			isHDCPKey1XExist = factorySetting.isHDCPKey1XExist();
			HdcpKey1_0 = isHDCPKey1XExist ? "OK" : "NG";
			keyMap.put("Hdcp1x", HdcpKey1_0);

			isHDCPKey2XExist = factorySetting.isHDCPKey2XExist();
			HdcpKey2_2 = isHDCPKey2XExist ? "OK" : "NG";
			keyMap.put("Hdcp2x", HdcpKey2_2);

			isDTVCIPlusKeyExist = factorySetting.isDTVCIPlusKeyExist();
			CIKey = isDTVCIPlusKeyExist ? "OK" : "NG";
			keyMap.put("CIKey", CIKey);

			isESNKeyExist = factorySetting.isNETFLIXKeyExist();
			ESNKey = isESNKeyExist ? "OK" : "NG";
			keyMap.put("ESNKey", ESNKey);

			isKeyMasterExist = factorySetting.isKeyMasterExist();
			KeyMaster = isKeyMasterExist ? "OK" : "NG";
			keyMap.put("KeyMaster", KeyMaster);

			isPlayReadyKeyExist = factorySetting.isPlayReadyKeyExist();
			PlayReadyKeyStr = isPlayReadyKeyExist ? "OK" : "NG";
			keyMap.put("PlayReady", PlayReadyKeyStr);

//			isPlayReady25KeyExist = factorySetting.isPlayReadyKey25Exist();
//			PlayReady25KeyStr = isPlayReady25KeyExist ? "OK" : "NG";
			
			isCLIENTCAkeyExist = factorySetting.isCLIENTCAKeyExist();
			CLIENTCAKeyStr = isCLIENTCAkeyExist ? "OK" : "NG";
			keyMap.put("CAKey", CLIENTCAKeyStr);

			isHashKeyExist = factorySetting.isHashKeyExist();
			HashKeyStr = isHashKeyExist ? "OK" : "NG";
			keyMap.put("HashKey", HashKeyStr);

			isMacExist = factorySetting.isMacExist();
			MacStr = isMacExist ? factorySetting.getMAC() : "NG";
			keyMap.put("Mac", MacStr);

			isDeviceIdExist = factorySetting.isDeviceIdExist();
			DeviceIdStr = isDeviceIdExist ? factorySetting.getDeviceID() : "NG";
			keyMap.put("DeviceId", DeviceIdStr);
			isESNIDExist = factorySetting.isESNIDExist();
			ESNID = isESNIDExist ? "OK" : "NG";

			isAllKeyExist = forHelpInfo(keyMap);

			/*
			 * isAllKeyExist =isMacExist && isDeviceIdExist && isHDCPKey1XExist &&
			 * isWidevineKeyExist && isKeyMasterExist && isPlayReadyKeyExist &&
			 * isHashKeyExist; if(factorySetting.isHdcp2xKeyNeeded()){
			 * isAllKeyExist=isAllKeyExist&&isHDCPKey2XExist; }
			 * if(factorySetting.isESNKeyNeeded()) { isAllKeyExist =
			 * isAllKeyExist && isESNKeyExist; }
			 * if(factorySetting.isCIKeyNeeded()){
			 * isAllKeyExist=isAllKeyExist&&isDTVCIPlusKeyExist; }
			 * if(factorySetting.isPlayReadyKey25Needed()){
			 * isAllKeyExist=isAllKeyExist && isPlayReady25KeyExist &&
			 * isCLIENTCAkeyExist; }
			 */

			/*
			 * WidevineKey = factorySetting.isWidevineKeyExist() ? "OK" :
			 * "Error"; HdcpKey1_0 = factorySetting.isHDCPKey1XExist() ? "OK" :
			 * "Error"; HdcpKey2_2 = factorySetting.isHDCPKey2XExist() ? "OK" :
			 * "Error"; CIKey = factorySetting.isDTVCIPlusKeyExist() ? "OK" :
			 * "Error"; ESNKey = factorySetting.isESNKeyExist() ? "OK" :
			 * "Error"; KeyMaster = factorySetting.isKeyMasterExist() ? "OK" :
			 * "Error";
			 * PlayReadyKeyStr=factorySetting.isPlayReadyKeyExist()?"OK"
			 * :"Error";
			 * HashKeyStr=factorySetting.isHashKeyExist()?"OK":"Error";
			 */
			// FactoryModeMenu.refresh(context);
			// mhandler.removeCallbacks(mRun);
			mhandler.post(new Runnable() {
				@Override
				public void run() {
					Widevine_Key.updateValue(WidevineKey);
					Widevine_Key
							.UpdateSpecialColor(isWidevineKeyExist ? Color.GREEN
									: Color.RED);

					HDCP_KEY_10.updateValue(HdcpKey1_0);
					HDCP_KEY_10
							.UpdateSpecialColor(isHDCPKey1XExist ? Color.GREEN
									: Color.RED);

					HDCP_KEY_22.updateValue(HdcpKey2_2);
					HDCP_KEY_22
							.UpdateSpecialColor(isHDCPKey2XExist ? Color.GREEN
									: Color.RED);

					CI_KEY.updateValue(CIKey);
					CI_KEY.UpdateSpecialColor(isDTVCIPlusKeyExist ? Color.GREEN
							: Color.RED);

					ESN_KEY.updateValue(ESNKey);
					ESN_KEY.UpdateSpecialColor(isESNKeyExist ? Color.GREEN
							: Color.RED);
					ESN_ID.updateValue(ESNID);
					ESN_ID.UpdateSpecialColor(isESNIDExist ? Color.GREEN
							: Color.RED);

					KEYMaster.updateValue(KeyMaster);
					KEYMaster.UpdateSpecialColor(isKeyMasterExist ? Color.GREEN
							: Color.RED);

					PlayReadyItem.updateValue(PlayReadyKeyStr);
					PlayReadyItem
							.UpdateSpecialColor(isPlayReadyKeyExist ? Color.GREEN
									: Color.RED);
					
					//PlayReady25Item.updateValue(PlayReady25KeyStr);
					//PlayReady25Item
					//		.UpdateSpecialColor(isPlayReady25KeyExist ? Color.GREEN
					//				: Color.RED);
					CLIENTCAItem.updateValue(CLIENTCAKeyStr);
					CLIENTCAItem
							.UpdateSpecialColor(isCLIENTCAkeyExist ? Color.GREEN
									: Color.RED);

					HashKeyItem.updateValue(HashKeyStr);
					HashKeyItem.UpdateSpecialColor(isHashKeyExist ? Color.GREEN
							: Color.RED);

					MAC_Address.updateValue(MacStr);
					MAC_Address.UpdateSpecialColor(isMacExist ? Color.GREEN
							: Color.RED);

					DeviceID.updateValue(DeviceIdStr);
					DeviceID.UpdateSpecialColor(isDeviceIdExist ? Color.GREEN
							: Color.RED);

					mFactoryActivity.setHelpInfo(isAllKeyExist?"OK":"NG");
					mFactoryActivity.setHelpInfoColor(isAllKeyExist?Color.GREEN:Color.RED);
				}
			});
		}
	};

	MenuItemData HDCP_KEY_10;
	MenuItemData HDCP_KEY_22;
	MenuItemData Widevine_Key;
	MenuItemData CI_KEY;
	MenuItemData ESN_KEY;
	MenuItemData ESN_ID;
	MenuItemData KEYMaster;
	MenuItemData PlayReadyItem;
	MenuItemData PlayReady25Item;
	MenuItemData CLIENTCAItem;
	MenuItemData HashKeyItem;
	MenuItemData MAC_Address;
	MenuItemData DeviceID;

	public List<MenuItemData> LoadPageData() {
		mListItemData.clear();

		// sw version
		String swVersion = getSWVersion();
		MenuItemData SW_Version = new MenuItemData(swVersion, "SW Version",
				swVersion, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// build time
		String buildTime = getSWDate();
		MenuItemData Build_Time = new MenuItemData(buildTime, "Built Time",
				buildTime, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// IP
		String IPAdd = factorySetting.getIPAdress();
		MenuItemData IP_Address = new MenuItemData(IPAdd, "IP", IPAdd,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// sw name
		//String UpgradeName = "upgrade_" + factorySetting.GetFirmwareTag()
		//		+ "_XXX.pkg";
		// sw name PHILCO
		String UpgradeNamePhilco = "PHCHDSGWA_V" + "XXX.bin";

		MenuItemData Upgrade_Name_Philco = new MenuItemData(UpgradeNamePhilco,
				"SW Name", UpgradeNamePhilco, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		/*MenuItemData Upgrade_Name = new MenuItemData(UpgradeName, "SW Name",
				UpgradeName, EN_ItemType.EN_OPTIONTEXTVIEW);*/

		// mboot version
		String MbootVersion = factorySetting.getBootVersion();
		MenuItemData Mboot_Version = new MenuItemData(MbootVersion,
				"Mboot Version", MbootVersion, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// product
		String productModel = factorySetting.getCurProductName();
		MenuItemData PorductName = new MenuItemData(productModel, "Product",
				productModel, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// panel
		String panelSelect = factorySetting.getPanelName();
		MenuItemData PanelName = new MenuItemData(panelSelect, "Panel",
				panelSelect, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// MAC addr
		String MACAddr = factorySetting.getMAC();
		MAC_Address = new MenuItemData(MACAddr, "MAC Address", MACAddr,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// // DeviceID addr
		String DeviceIDStr = factorySetting.getDeviceID();
		DeviceID = new MenuItemData(DeviceIDStr, "Device ID", DeviceIDStr,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// *hdcp key 1.0
		HdcpKey1_0 = "Checking...";// factorySetting.getHDCPKey1x_CheckSum()?"OK":"Error";
		HDCP_KEY_10 = new MenuItemData(HdcpKey1_0, "HDCP KEY1.0", HdcpKey1_0,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// *hdcp key 2.0
		HdcpKey2_2 = "Checking...";// factorySetting.getHDCPKey2x_CheckSum()?"OK":"Error";
		HDCP_KEY_22 = new MenuItemData(HdcpKey2_2, "HDCP KEY2.0", HdcpKey2_2,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// *widevine key
		WidevineKey = "Checking...";// factorySetting.getWidevine_Key_CheckSum()?"OK":"Error";
		Widevine_Key = new MenuItemData(WidevineKey, "Widevine Key",
				WidevineKey, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// *ci key
		CIKey = "Checking...";//
		CI_KEY = new MenuItemData(CIKey, "CI + Key", CIKey,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		ESNKey = "Checking...";//
		ESN_KEY = new MenuItemData(ESNKey, "Netflix Key", ESNKey,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		ESNID = "Checking...";//
		ESN_ID = new MenuItemData(ESNID, "ESNID", ESNID,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		KeyMaster = "Checking...";//
		KEYMaster = new MenuItemData(KeyMaster, "KeyMaster", KeyMaster,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);
		PlayReadyKeyStr = "Checking...";//
		PlayReadyItem = new MenuItemData(PlayReadyKeyStr, "PlayReadyKey",
				PlayReadyKeyStr, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);
		PlayReady25KeyStr = "Checking...";//
		PlayReady25Item = new MenuItemData(PlayReady25KeyStr, "PlayReady2.5Key",
				PlayReady25KeyStr, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);
		CLIENTCAKeyStr = "Checking...";//
		CLIENTCAItem = new MenuItemData(CLIENTCAKeyStr, "CLIENTCAKey",
				CLIENTCAKeyStr, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);
		HashKeyStr = "Checking...";//
		HashKeyItem = new MenuItemData(HashKeyStr, "HashKey", HashKeyStr,
				MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		// MAC addr
		// BenQ
		MenuItemData LigthSensorValue = null;
		/*
		 * //zcj 2018-10-31if(SystemProperties.get("ro.product.brand",
		 * "CHANGHONG").equals( "BenQ")){ String ligthSensorValue=
		 * factorySetting.getLightSensorValue(); LigthSensorValue = new
		 * MenuItemData(ligthSensorValue,
		 * "LightSensor",ligthSensorValue,EN_ItemType.EN_OPTIONTEXTVIEW); }
		 */
		Log.v("factory", "runnable start");
		// mhandler.postDelayed(mRun, 1);
		Log.v("factory", "runnable end");

		// Runnable r=new Runnable(){
		// @Override
		// public void run() {
		// // TODO Auto-generated method stub
		// //System.out.println("thread");
		// Log.v("factory","start sync Runnable");
		// mhandler.postDelayed(mRun, 10);
		// }
		// };
		//

		// product
		String projectId = factorySetting.getCurProjectIndex();
		MenuItemData ProjectId = new MenuItemData(projectId, context
				.getResources().getString(
						R.string.factory_pagezero_project_projectid),
				projectId, MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);
		 final AlertDialog.Builder builder = new AlertDialog.Builder(context);
		 builder.setMessage(projectId);
		 builder.setPositiveButton("OK", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// TODO Auto-generated method stub
			}
		});
		ProjectId.setOnEnterKey(new MenuItemData.onEnterRightKey() {
			
			@Override
			public void onEnterRightKey() {
				// TODO Auto-generated method stub
				builder.show();
			}
		});
		
		MenuItemData  KeyStatusShow= new MenuItemData("KeyStatus Show");
		KeyStatusShow.setOnEnterKey(new MenuItemData.onEnterRightKey() {

			public void onEnterRightKey() {
				Log.v("tv", "KeyStatus onkey");
				if (factorySetting.getKeyStatusIniFileExist()) {
					// String str = null;

					// str = "MAC="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_MAC)
					// 		+ "\n DEVICEID="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_DEVICEID)
					// 		+ "\n HDCPKEY14="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_HDCPKEY14)
					// 		+ "\n WIDEVINE="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_WIDEVINE)
					// 		+ "\n KEYMASTER="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_KEYMASTER)
					// 		+ "\n PLAYREADY="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_PLAYREADY)
					// 		+ "\n PLAYREADY1="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_PLAYREADY_1)
					// 		+ "\n PLAYREADY2="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_PLAYREADY_2)
					// 		+ "\n PLAYREADY25="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_PLAYREADY25)
					// 		+ "\n PLAYREADY25_1="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_PLAYREADY25_1)
					// 		+ "\n PLAYREADY25_2="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_PLAYREADY25_2)
					// 		+ "\n HASHKEY="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_HASHKEY)
					// 		+ "\n HDCPKEY2="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_HDCPKEY2)
					// 		+ "\n NETFLIX="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_NETFLIX)
					// 		+ "\n NETFLIX_ESN="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_NETFLIX_ESN_KEY)
					// 		+ "\n CI="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_CI)
					// 		+ "\n CA="
					// 		+ MtkTvFApiInformation.getInstance().getIniParameter(Contants.KEYSTATUS_INI_FILEPATH,
					// 				Contants.KEYSTATUS_CAKEY)
					// 		+ "\n TVWORKTIME=" + MtkTvFApiInformation.getInstance()
					// 				.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_TVWORKTIME);
					// showToast(str);
					Intent KsyStatusIntent = new Intent();
					KsyStatusIntent.setComponent(new ComponentName(
							"com.homwee.factory",
							"com.homwee.factory.FactoryListInfoActivity"));
					KsyStatusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					KsyStatusIntent.putExtra("CheckItem", KEY_STATUS_CHECK);
					context.startActivity(KsyStatusIntent);
				} else {
					showToast(context
							.getString(R.string.factory_pagetwo_keystatusini_file_no_exits));
				}
			}
		});
		
		// worktime addr
		String WorkTimeStr = factorySetting.getTvWorkTime();
		MenuItemData TvWorktime = new MenuItemData(WorkTimeStr, "Tv Work Time", WorkTimeStr,
						MenuItemData.EN_ItemType.EN_OPTIONTEXTVIEW);

		Thread thread = new Thread(mRun);
		thread.start();
		Log.v("factory", "thread.start");
		Log.v("factory", "cur product="+mProduct);

		mListItemData.add(ProjectId);
		mListItemData.add(PanelName);
		mListItemData.add(MAC_Address);
		mListItemData.add(DeviceID);
		mListItemData.add(HDCP_KEY_10);
		if(!(mProduct.contains("86")||mProduct.contains("61"))){
            mListItemData.add(HDCP_KEY_22);
        }
		mListItemData.add(Widevine_Key);
		mListItemData.add(KEYMaster);
		mListItemData.add(ESN_KEY);
		mListItemData.add(PlayReadyItem);
//		mListItemData.add(PlayReady25Item);
        if(mProduct.contains("DVB")) {
            mListItemData.add(CI_KEY);
            mListItemData.add(CLIENTCAItem);
        }
		mListItemData.add(HashKeyItem);
		if(mProduct.contains("ISDB") && mBrand.equals("Philco"))
		{
			mListItemData.add(ESN_ID);
		}
		mListItemData.add(IP_Address);
		//mListItemData.add(Upgrade_Name);
		mListItemData.add(SW_Version);
		mListItemData.add(Build_Time);
		
		if(factorySetting.isFactoryShowNoFunc()){
			mListItemData.add(Mboot_Version);
		}
		mListItemData.add(KeyStatusShow);
		mListItemData.add(TvWorktime);

		return mListItemData;
	}

	public String getSWVersion() {
		// TODO Auto-generated method stub
		return factorySetting.getSWVersion();
	}

	public String getSWDate() {
		// TODO Auto-generated method stub
		return factorySetting.getSWDate();
	}
	
	public void showToast(String str) {
        if (mToast == null) {
            mToast = Toast.makeText(context, str, 5000);
        } else {
            mToast.setText(str);
            mToast.setDuration(5000 + 5000);
        }
        mToast.show();
    }
	public boolean forHelpInfo(Map<String, String> keymap) {

		Log.d("zcj", "=========+" + mProduct + "================");

		//temp fix eeprom install key issue
//		if (mProduct.contains("ISDB")) {
//			boolean isAllKeyExist = isMacExist && isDeviceIdExist && isHDCPKey1XExist && isWidevineKeyExist
//					&& isKeyMasterExist && isPlayReadyKeyExist && isHashKeyExist;
//			if (factorySetting.isHdcp2xKeyNeeded()) {
//				isAllKeyExist = isAllKeyExist && isHDCPKey2XExist;
//			}
//			if (factorySetting.isESNKeyNeeded()) {
//				isAllKeyExist = isAllKeyExist && isESNKeyExist;
//			}
//			if (factorySetting.isCIKeyNeeded()) {
//				isAllKeyExist = isAllKeyExist && isDTVCIPlusKeyExist;
//			}
//			if (factorySetting.isPlayReadyKey25Needed()) {
//				isAllKeyExist = isAllKeyExist && isCLIENTCAkeyExist;
//			}
//			return isAllKeyExist;
//		} else {
			boolean ret = false;
			for (Map.Entry<String, String> entry : keymap.entrySet()) {
				switch (entry.getKey().toUpperCase()) {
					case "WIDEVINE": {
						if (entry.getValue().equalsIgnoreCase("OK")) {
							String widevineStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_WIDEVINE);
							if (widevineStr.isEmpty() || widevineStr == null) {
								keymap.put("Widevine", "OK");
								break;
							}
							if (!widevineStr.equalsIgnoreCase("OK")) {
								if (widevineStr.contains("encrypt")) {
									boolean reloadRet = factorySetting.taKeyReload("WIDEVINE");
									if (reloadRet) {
										keymap.put("Widevine", "OK");
									} else {
										keymap.put("Widevine", "NG");
									}
								} else {
									keymap.put("Widevine", "NG");
								}
							}
						}
						break;
					}
					case "HDCP1X": {
						if (entry.getValue().equalsIgnoreCase("OK")) {
							String hdcp1xStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_HDCPKEY14);
							if (hdcp1xStr.isEmpty() || hdcp1xStr == null) {
								keymap.put("Hdcp1x", "OK");
								break;
							}
							if (!hdcp1xStr.equalsIgnoreCase("OK")) {
								if (hdcp1xStr.contains("encrypt")) {
									boolean reloadRet = factorySetting.taKeyReload("HDCP1X");
									if (reloadRet) {
										keymap.put("Hdcp1x", "OK");
									} else {
										keymap.put("Hdcp1x", "NG");
									}
								} else {
									keymap.put("Hdcp1x", "NG");
								}
							}
						}
						break;
					}
					case "HDCP2X":
						if (factorySetting.isHdcp2xKeyNeeded()) {
							if (entry.getValue().equalsIgnoreCase("OK")) {
								String hdcp2xStr = MtkTvFApiInformation.getInstance()
										.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_HDCPKEY2);
								if (hdcp2xStr.isEmpty() || hdcp2xStr == null) {
									keymap.put("Hdcp2x", "OK");
									break;
								}
								if (!hdcp2xStr.equalsIgnoreCase("OK")) {
									if (hdcp2xStr.contains("encrypt")) {
										boolean reloadRet = factorySetting.taKeyReload("HDCP2X");
										if (reloadRet) {
											keymap.put("Hdcp2x", "OK");
										} else {
											keymap.put("Hdcp2x", "NG");
										}
									} else {
										keymap.put("Hdcp2x", "NG");
									}

								}
							}
						} else {
							keymap.put("Hdcp2x", "No Need");
						}
						break;
					case "CIKEY":
						if (factorySetting.isCIKeyNeeded()) {
							if (entry.getValue().equalsIgnoreCase("OK")) {
								String ciKeyStr = MtkTvFApiInformation.getInstance()
										.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_CI);
								if (ciKeyStr.isEmpty() || ciKeyStr == null) {
									keymap.put("CIKey", "OK");
									break;
								}
								if (!ciKeyStr.equalsIgnoreCase("OK")) {
									keymap.put("CIKey", "NG");
								}
							}
						} else {
							keymap.put("CIKey", "No Need");
						}
						break;
					case "ESNKEY":
						if (factorySetting.isESNKeyNeeded()) {
							if (entry.getValue().equalsIgnoreCase("OK")) {
								String esnStr = MtkTvFApiInformation.getInstance().getIniParameter(
										Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_NETFLIX_ESN_KEY);
								String nfStr = MtkTvFApiInformation.getInstance()
										.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_NETFLIX);

								if ((esnStr.isEmpty() || esnStr == null) || (nfStr.isEmpty() || nfStr == null)) {
									keymap.put("ESNKey", "OK");
									break;
								}

								if (!esnStr.equalsIgnoreCase("OK") || !nfStr.equalsIgnoreCase("OK")) {
									keymap.put("ESNKey", "NG");
								}
								if (nfStr.contains("encrypt")) {
									boolean reloadRet = factorySetting.taKeyReload("NETFLIX");
									if (reloadRet && esnStr.equalsIgnoreCase("OK")) {
										keymap.put("ESNKey", "OK");
									}
								}
							}
						} else {
							keymap.put("ESNKey", "No Need");
						}
						break;
					case "KEYMASTER":
						if (entry.getValue().equalsIgnoreCase("OK")) {
							String keyMasterStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_KEYMASTER);
							String pidStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_PID);
							if (keyMasterStr.isEmpty() || keyMasterStr == null
									|| pidStr.isEmpty() || pidStr == null) {
								//check PID for distinguish old keystatus.ini
								keymap.put("KeyMaster", "OK");
								break;
							}
							if (!keyMasterStr.equalsIgnoreCase("OK")) {
								if (keyMasterStr.contains("encrypt")) {
									boolean reloadRet = factorySetting.taKeyReload("KEYMASTER");
									if (reloadRet) {
										keymap.put("KeyMaster", "OK");
									} else {
										keymap.put("KeyMaster", "NG");
									}
								} else {
									keymap.put("KeyMaster", "NG");
								}
							}
						}
						break;
					case "PLAYREADY":
						if (entry.getValue().equalsIgnoreCase("OK")) {
							String playReadyStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_PLAYREADY);
							if (playReadyStr.isEmpty() || playReadyStr == null) {
								keymap.put("PlayReady", "OK");
								break;
							}
							if (!playReadyStr.equalsIgnoreCase("OK")) {
								if (playReadyStr.contains("encrypt")) {
									boolean reloadRet = factorySetting.taKeyReload("PLAYREADY");
									if (reloadRet) {
										keymap.put("PlayReady", "OK");
									} else {
										keymap.put("PlayReady", "NG");
									}
								}else if(playReadyStr.equalsIgnoreCase("PRESET")){
									boolean reloadRet = factorySetting.taKeyReload("PLAYREADY");
								}else {
									keymap.put("PlayReady", "NG");
								}
							}
						}
						break;
					case "CAKEY":
						if (factorySetting.isPlayReadyKey25Needed()) {
							if (entry.getValue().equalsIgnoreCase("OK")) {
								String caStr = MtkTvFApiInformation.getInstance()
										.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_CAKEY);
								if (caStr.isEmpty() || caStr == null) {
									keymap.put("CAKey", "OK");
									break;
								}
								if (caStr.contains("NG")) {
									keymap.put("CAKey", "NG");
								}
							}
						} else {
							keymap.put("CAKey", "No Need");
						}
						break;
					case "HASHKEY":
						if (entry.getValue().equalsIgnoreCase("OK")) {
							String hashStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_HASHKEY);
							if (hashStr.isEmpty() || hashStr == null) {
								keymap.put("HashKey", "OK");
								break;
							}
							if (hashStr.contains("NG")) {
								keymap.put("HashKey", "NG");
							}
						}
						break;
					case "MAC":
						if (!entry.getValue().equalsIgnoreCase("NG")) {
							keymap.put("Mac", "OK");
						}
						break;
					case "DEVICEID":
						if (!entry.getValue().equalsIgnoreCase("NG")) {
							String deviceIdStr = MtkTvFApiInformation.getInstance()
									.getIniParameter(Contants.KEYSTATUS_INI_FILEPATH, Contants.KEYSTATUS_DEVICEID);
							if (deviceIdStr.isEmpty() || deviceIdStr == null) {
								keymap.put("DeviceId", "OK");
								break;
							}
							if (deviceIdStr.contains("NG")) {
								keymap.put("DeviceId", "NG");
							} else {
								keymap.put("DeviceId", "OK");
							}
						}
						break;
					default:
						break;
				}
			}

			int keyNum = 0;
			int okNum = 0;
			for (Map.Entry<String, String> entry : keymap.entrySet()) {
				keyNum++;
				if (entry.getValue().equalsIgnoreCase("OK") || entry.getValue().equalsIgnoreCase("No Need")) {
					okNum++;
				}
				Log.d("zcj", "=====+" + entry.getKey() + "=====" + entry.getValue());
			}
			Log.d("zcj", "=====keyNum:" + keyNum + ";okNum:" + okNum);
			if (keyNum == okNum) {
				ret = true;
			}
			return ret;
		}
	}
